﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KNXObjects
{
    public class ScaledObject : GenericObjectBase<uint>
    {
        #region ObjectBase Implementations

        public override string DataPointEISName
        {
            get { return "EIS6"; }
        }

        public override string DataPointID
        {
            get { return "5.001"; }
        }

        public override string ToString()
        {
            return ((float)Value * 100 / 255).ToString("#.###");
        }

        public override void SetValue(string value)
        {
            uint val;
            if (uint.TryParse(value, out val))
            {
                if (val > 100)
                    throw new ApplicationException("ScaledObject: Value shoud be contained between 0 and 100. Val : " + value);

                Value = val;

            }
            else
                throw new ApplicationException("ScaledObject: Cannot convert to uint. Val : " + value);
        }

        #endregion

        #region ctor

        public ScaledObject(string id, string address, string name, string flags)
            : base(id, address, name, flags)
        {
        }

        public ScaledObject(string value)
        {
            SetValue(value);
        }

        #endregion
    }
}
